package vikaa.adapter;

import java.util.ArrayList;

import vikaa.bean.WeiboFriend;
import vikaa.wowo.R;



import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class ContactFriendListAdapter extends BaseAdapter{
	private Context context;
	private LayoutInflater inflater;
	private final ArrayList<WeiboFriend>  wbList; 
	private ListView listView;
    
    public ContactFriendListAdapter(Context context, ArrayList<WeiboFriend> wbList,ListView listView) {
		super();
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.wbList = wbList;
		this.listView = listView;
	}

    public int getCount() {
        return wbList.size();
    }

    public Object getItem(int position) {
        return wbList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

	public View getView(int position, View convertView, ViewGroup parent) {
		Holder wh;
		if(convertView == null){
		convertView = inflater.inflate(R.layout.wbfriend_item, null);
        wh = new Holder();
        wh.name = (TextView) convertView.findViewById(R.id.nameTv);
        wh.choose = (ImageView)convertView.findViewById(R.id.chooseImg);
        wh.phone = (TextView)convertView.findViewById(R.id.phoneTv);
        convertView.setTag(wh);
		}
		else
			wh = (Holder)convertView.getTag();
        WeiboFriend wb = wbList.get(position);
        if(wb!=null){
            wh.name.setText(wb.getName());
            wh.phone.setText(wb.getPhone());
            if(wb.isSelected()){
            	wh.choose.setVisibility(View.VISIBLE);
            }
            else
            	wh.choose.setVisibility(View.INVISIBLE);
        }
        return convertView;
	}
	public void changeState(int position,View view){
		wbList.get(position).setId(wbList.get(position).getId());	
		wbList.get(position).setName(wbList.get(position).getName());
		wbList.get(position).setSelected(!(wbList.get(position).isSelected()));
    	notifyDataSetChanged();
    }
	static class Holder {
		public TextView name = null;
		public TextView phone = null;
		public ImageView choose = null;
	}

}
